# -*- coding: utf-8 -*-
from __future__ import print_function, division
#系统库
import os
import sys
#第三方库
#自定义库
import Serverlib
import Serverlib.game

logger = Serverlib.logging.getLogger('SERVER')


#初始化
def load():
    path = os.path.dirname(__file__)
    sys.path.append(path)
    for filename in filter(lambda x: not x.startswith('__') and x.endswith('.py'), os.listdir(path)):
        modname = filename.replace(".py", "")
        __import__(modname).on_load()
        pass


def load_fsm_prop(proplist):
    for item in proplist:
        Serverlib.game.FSM.reg_prop(item[0], item[1])


def load_player_prop(proplist):
    for item in proplist:
        Serverlib.game.Player.reg_prop(item[0], item[1])


def load_event_handlers(cls, modulename):
    for member in filter(lambda x: not x.startswith('_'), dir(cls)):
        func = None
        exec("func = cls.{0}".format(member))
        Serverlib.game.FSM.register_action(member, func, modulename)


def load_fsm_funcs(cls, modulename):
    for member in filter(lambda x: not x.startswith('_'), dir(cls)):
        func = None
        exec("func = cls.{0}".format(member))
        Serverlib.game.FSM.reg_func(member, func)
    pass
